package com.charon.common.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
  *@ClassName: SwaggerConfig
  *@Description: Swagger2配置类
  *         在与spring boot集成时，放在与Application.java同级的目录下。
  *@Author: Charon [248135724@qq.com]
  *@Date: 2019/1/24 0024 17:56
  *@Version: 1.0
  */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.charon"))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 创建该API的基本信息（这些基本信息会展现在文档页面中）
     * 访问地址：http://项目实际地址/swagger-ui.html
     * @return
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Charon - RESTful - API")
                .description("Charon聚合文档API")
                .termsOfServiceUrl("http://www.charon.fun")
                .contact(new Contact("charon","http://charon.fun","248135724@qq.com"))
                .version("0.0.1")
                .build();
    }

}
